define(function(require, exports, module) {
    var ALL = require("../../common/all"),
        CONFIG = ALL.CONFIG,
        Dialog = ALL.Dialog,
        METHOD = ALL.METHOD,
        Init = ALL.Init;

    var _Dialog = new Dialog({
        title : "提示",
        content : "<p>是否确认将该藏品设置为临时停牌？</p>",
        text4Btn: ["确定", "取消"],
        class4Btn: ["", "line"]
    });
    var _vm = Init.initVue({
        data : {
            list: [],
            check: {},
            self: {
                id: '',
                type : 1,
                time_type: []
            },
        },
        methods: {
            submit : function(item,sub) {
                var obj;

                if (!sub) {
                    _vm.check.$valid();
                    if (!_vm.check.flag) { return; }
                    item = _vm.self;
                } else {
                    if (item.type == 0 && !item.time_type[0].start && !item.time_type[0].end) {
                        METHOD.alert("请选择临停开始/结束时间");
                        return;
                    }
                }

                obj = {
                    type: 1,
                    col_id: item.id,
                    time_type: item.time_type[item.type].type,
                    start_time: item.time_type[item.type].start,
                    end_time: item.time_type[item.type].end
                };


                if (obj.start_time > obj.end_time || obj.start_time == obj.end_time) {
                    METHOD.alert("临停开始时间不能早于结束时间，请重新设置。")
                    return;
                }

                _Dialog.showUI(function(i){
                    if (i == 0) {
                        METHOD.loading.show();
                        METHOD.ajax("tradesuspend/create",{data: JSON.stringify(obj) },{type : 'post'}).done(function(){
                            METHOD.loading.hide();
                            METHOD.alert("操作成功").done(function(){
                                window.location.href = "../control/pause.html";
                            });
                        }).fail(function(){
                            METHOD.loading.hide();
                        });
                    }
                    this.hideUI();
                });
            }
        }
    });

    METHOD.loading.show();
    METHOD.ajax("tradesuspend/monitor",{}).done(function(json){
        METHOD.loading.hide();
        _vm.list = json.data;
    }).fail(function(){
        METHOD.loading.hide();
    });

    METHOD.loading.show();
    METHOD.ajax("tradesuspend/time_list",{type:1}).done(function(json){
        METHOD.loading.hide();
        _vm.self.time_type = json.data;
    }).fail(function(){
        METHOD.loading.hide();
    });

    _vm.self.id = METHOD.getQueryParms("cid") || "";
});

